fix: Fix collision prospect checking to be fully reliable#3905
Merged
Conversation
74b5ae1 to
51ace92
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix collision prospect checking to be fully reliable.
Turns out there is still a high-percent chance of hash collisions even with #3864 on our tests, causing CI flakyness.
This completely bypasses the issue by making the code collision-resistent to begin with. This is orthogonal to improving hashing collision rate.
At first I added my own implementation of Set but then realize that we can just use Dart's set, if we are clever about it. It already handles collisions elegantly (i.e. with no performance penalty if there are no collisions), by using a flat array with index fallbacks. Every recover check pays one hash and at least one identity check which are very cheap.
We just need to implement hashCode and equals, the hash can use the existing approximation, and the equals can use the unordered identity check.
This bulks up the pool implementation to hide the "mutable" view over
CollisionProspect, which I made a immutable first-class citizen. No one can mutate the prospect other than the pool, that owns the lifecycle.At the end of the day there was no reason for these sets to be a map keyed on hashcode. That is just a poor-mans set!
I dare say it is impossible for the CI to flake now :P
Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?